package heraclito;

import Dados.Exemplos;
import Dados.Parametros;
import org.jdesktop.application.Action;

public class SelecaoExemplos extends javax.swing.JPanel {

    private Exemplos Ex;
    private int indexAba;

    public SelecaoExemplos(int indexAba) {
        initComponents();

        jComboBox1.setEnabled(false);
        btnIniciar.setEnabled(false);
        this.indexAba = indexAba;
        //Carrega a variaveis que carrega os exemplos
        Ex = new Exemplos(Parametros.Diretorio_Exemplos);
        txtExemplo.setText("");//Limpa a lista de exemplos
        //Carrega as pastas do diretório padrão que são os níveis de dificuldade dos exemplos
        String[] aux = Ex.getNiveisExemplos().split("\n");
        for (int x = 0; x < aux.length; ++x) {
            jComboBox2.addItem(aux[x]);
        }
    }

    @Action
    public void setComboBox1() {
        jComboBox1.removeAllItems();
        jComboBox1.setEnabled(true);
        btnIniciar.setEnabled(true);
        String[] aux = Ex.getExemplos(jComboBox2.getSelectedItem().toString()).split("\n");
        for (int x = 0; x < aux.length; ++x) {
            jComboBox1.addItem(aux[x].substring(0, aux[x].length()));
        }
    }

    @Action
    public void setTxtExemplos() {
        txtExemplo.setText(Ex.getExemplo(jComboBox2.getSelectedItem().toString(), jComboBox1.getSelectedItem().toString()+".txt"));
    }

    public int getIndexAba() {
        return indexAba;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        txtExemplo = new javax.swing.JTextArea();
        btnIniciar = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();

        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        txtExemplo.setColumns(20);
        txtExemplo.setEditable(false);
        txtExemplo.setRows(5);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(heraclito.HeraclitoApp.class).getContext().getResourceMap(SelecaoExemplos.class);
        txtExemplo.setText(resourceMap.getString("txtExemplo.text")); // NOI18N
        txtExemplo.setName("txtExemplo"); // NOI18N
        jScrollPane1.setViewportView(txtExemplo);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(heraclito.HeraclitoApp.class).getContext().getActionMap(SelecaoExemplos.class, this);
        btnIniciar.setAction(actionMap.get("setTxtExemplos")); // NOI18N
        btnIniciar.setText(resourceMap.getString("btnIniciar.text")); // NOI18N
        btnIniciar.setName("btnIniciar"); // NOI18N

        jComboBox2.setAction(actionMap.get("setComboBox1")); // NOI18N
        jComboBox2.setName("jComboBox2"); // NOI18N

        jComboBox1.setName("jComboBox1"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setPreferredSize(new java.awt.Dimension(100, 17));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnIniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnIniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnIniciar;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtExemplo;
    // End of variables declaration//GEN-END:variables
}
